package everyday;

import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2023-06-10-19:47
 * @Description: 1.0
 */
public class T1170 {
    public int[] numSmallerByFrequency(String[] queries, String[] words) {
        int m = words.length;
        int[] cnt = new int[11];
        for (int i = 0; i < m; i++) {
            cnt[f(words[i])]++;
        }
        for (int i = 1; i < 11; i++) {
            cnt[i] += cnt[i - 1];
        }
        int n = queries.length;
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = m - cnt[f(queries[i])];
        }
        return res;
    }

    public int f(String s) {
        int minNum = 0;
        char minChar = 'z';
        for (char c : s.toCharArray()) {
            if (c < minChar) {
                minChar = c;
                minNum = 1;
            } else if (c == minChar) {
                minNum++;
            }
        }
        return minNum;
    }
}
